<?php

/**
 * oRs
 *
 * @version 3.0
 * @copyright 2009 Ron Planken
 * @class: events
 * @description: Handles the actions for events
 */
 
class events {
	
	private $_system;
	
	function __construct($system) {
		$this->_system = $system;
	}
	
	function get($event_id = 0){

		$event_id = $this->_system->_db->secure_int($event_id);

		if ($event_id == 0) {
			$query ='SELECT  event_id
			                ,name
			                ,description
						FROM event
					   WHERE status = 0
					GROUP BY event_id;
							';
		} else {
			$query = "SELECT event_id
			                ,name
			                ,description
						FROM event
					   WHERE event_id = $event_id;
					   	 AND status = 0
							";
		}

		$events = $this->_system->_db->SelectMultiQuery($query);

		return $events;

	}


	function save($event_id, $name, $description) {

    $event_id = $this->_system->_db->secure_int($event_id);
    $name = $this->_system->_db->secure_string($name);
    $description = $this->_system->_db->secure_string($description);

		if ($event_id == 0) {
			$query ="INSERT INTO event
						   			 ( event_id
			                ,name
			                ,description
						          )
							VALUES ( $event_id
			                ,$name
			                ,$description
						  				)
											";
			$status = $this->_system->_db->InsertQuery($query);

		} else {
			$query ="UPDATE  event
									SET  name = $name
			                ,description = $description
					  WHERE event_id = $event_id
							";
			$status = $this->_system->_db->UpdateQuery($query);
		}

		return $status;

	}

	function remove($event_id = 0) {

		$event_id = $this->_system->_db->secure_int($event_id);

		$query ="UPDATE event
				  	SET status = 1
				  WHERE event_id = $event_id;
							";
		$status = $this->_system->_db->UpdateQuery($query);

		return $status;
	}

}
?>